package actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import dao.AktieDAO;

public class DividendeAction extends Action{

	@Override
	public String execute(HttpServletRequest request, HttpSession s)
			throws Exception {
		
		//Validierung
		if (request.getParameter("min").equals("")
				|| request.getParameter("max").equals("")
				|| request.getParameter("streuung").equals("")){
			
			setApplicationMessage(s, getMessageProperty("angabenNichtKomplett"));
			return getForwardProperty("dividende");
		}
				
		try{
			if(!AktieDAO.getInstance().berechneDividende(Integer.valueOf(request.getParameter("min")), Integer.valueOf(request.getParameter("max")), request.getParameter("streuung"))){
				setApplicationMessage(s, getMessageProperty("unerwarteterFehler"));
				return getForwardProperty("dividende");
			}else{
				setApplicationMessage(s, getMessageProperty("dividendeAusgeschuettet"));
				return getForwardProperty("admin");
			}
		}catch(NumberFormatException e){
			setApplicationMessage(s, getMessageProperty("angabenNichtKorrekt"));
			return getForwardProperty("dividende");
		}
	}
}
